package com.ccp.dev.core.basic.util;

import java.util.UUID;

/**
 * @Author: dfz
 * @Date: 2019/3/4 11:19
 * @Description: UUID工具类
 */
public class UUIDUtils {

    /**
     * 功能描述: 获取32位的UUID随机码(去除"-")
     *
     * @return java.lang.String
     * @author dfz
     * @date 2019/3/4 11:21
     */
    public static String getUUIDFor32() {

        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 功能描述: 生成Long类型主键ID
     *
     * @return java.lang.String
     */
    public static Long getLongId(){
        //随机生成一位整数
        int random = (int) (Math.random()*999999);
        String val = String.format("%06d",random);
        String valueOf = String.valueOf(val);
        //生成uuid的hashCode值
        int hashCode = UUID.randomUUID().toString().hashCode();
        //可能为负数
        if(hashCode<0){
            hashCode = -hashCode;
        }
        String value = String.format("%010d", hashCode)+valueOf;
        Long valueToLong = Long.parseLong(value);
        return valueToLong;
    }
}
